package com.cmwa.solution.business.prdSetup.standardPrjTemplate.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.cmwa.solution.base.entity.Page;
import com.cmwa.solution.base.entity.SearchParam;
import com.cmwa.solution.business.prdSetup.standardPrjTemplate.dao.StandardPrjTemplateDao;
import com.cmwa.solution.business.prdSetup.standardPrjTemplate.entity.StandardPrjTemplateVo;
import com.cmwa.solution.business.prdSetup.standardPrjTemplate.service.StandardPrjTemplateService;
import com.cmwa.solution.sys.attach.service.AttachService;
import com.cmwa.solution.utils.SessionUtils;

/**
 * 标准理财产品模板业务实现层
 * 
 * @author ex-zuotc
 * @date 2019-01-24 10:25:48
 */
@Service
public class StandardPrjTemplateServiceImpl implements StandardPrjTemplateService {
	@Resource
	private StandardPrjTemplateDao standardPrjTemplateDao;
	
	@Resource
	private AttachService attachService;
	
		
	@Override
	public void saveStandardPrjTemplate(StandardPrjTemplateVo standardPrjTemplate, String attIds) {
		String empId = SessionUtils.getEmployee().getID();
		standardPrjTemplate.setStatus("C");
		if (StringUtils.isEmpty(standardPrjTemplate.getId())) {
			standardPrjTemplate.setCreateId(empId);
			standardPrjTemplateDao.insertStandardPrjTemplate(standardPrjTemplate);
		} else {
			standardPrjTemplate.setModifyId(empId);
			standardPrjTemplateDao.updateStandardPrjTemplateById(standardPrjTemplate);
		}
		String relType = "STANDARD_PRD_TEMPLATE";
		attachService.deleteAttachRel2(standardPrjTemplate.getId(), relType);
		if (StringUtils.isNotEmpty(attIds)) {
			attachService.addAttachRel2(empId, standardPrjTemplate.getId(), relType, attIds);
		}
	}
		
		
	@Override
	public void physicDeleteStandardPrjTemplateById(String id) {
		standardPrjTemplateDao.physicDeleteStandardPrjTemplateById(id);
	}
	
		
		
	@Override
	public void logicDeleteStandardPrjTemplateById(String id) {
		standardPrjTemplateDao.logicDeleteStandardPrjTemplateById(id);
	}
	
		
		
	@Override
	public void updateStandardPrjTemplateById(StandardPrjTemplateVo standardPrjTemplate) {
		standardPrjTemplateDao.updateStandardPrjTemplateById(standardPrjTemplate);
	}
	
		
		
	@Override
	public Page<StandardPrjTemplateVo> standardPrjTemplateListPage(SearchParam sp) {
		List<StandardPrjTemplateVo> items = standardPrjTemplateDao.standardPrjTemplateListPage(sp);
		return Page.create(items, sp.getStart(), sp.getLimit(), sp.getTotal());
	}
	
		
		
	@Override
	public StandardPrjTemplateVo getStandardPrjTemplateById(String id) {
		return standardPrjTemplateDao.getStandardPrjTemplateById(id);
	}
	
	@Override
	public List<StandardPrjTemplateVo> queryList(StandardPrjTemplateVo templateVo) {
		return standardPrjTemplateDao.queryList(templateVo);
	}
	
}
